package cn.itsource.pethome.quartz.service.impl;

import cn.itsource.pethome.quartz.domain.QuartzJobInfo;
import cn.itsource.pethome.quartz.job.QuartzJob;
import cn.itsource.pethome.quartz.service.IQuartzService;
import cn.itsource.pethome.quartz.util.QuartzUtils;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

/**
 * @description: 描述:
 * @date: 2020/8/28 15:49
 * @author: summer
 * version: 1.0
 */
@Service
public class QuartzServiceImpl implements IQuartzService {

    @Autowired
    private SchedulerFactoryBean schedulerFactoryBean;

    @Override
    public void addJob(QuartzJobInfo jobInfo) {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        QuartzUtils.addJob(scheduler,jobInfo.getJobName() ,
                QuartzJob.class, jobInfo,jobInfo.getCronj() );

    }

    @Override
    public void removeJob(String jobName) {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        QuartzUtils.removeJob(scheduler,jobName );

    }
}
